package vn.edu.saigontech.ncms.web.system;

import vn.edu.saigontech.ncms.model.system.Parameter;
import vn.edu.saigontech.ncms.model.system.USD;
import vn.edu.saigontech.ncms.service.ParameterService;
import vn.edu.saigontech.ncms.service.impl.USDServiceImpl;
import vn.edu.saigontech.ncms.web.BaseAction;

@SuppressWarnings("serial")
public class ParameterAction extends BaseAction {
	
	private Long id;
	private String name;
	private String value;
	private String comment;
	
	public String list() {
		REQUEST().setAttribute("parameters", ParameterService.INSTANCE.findAll());
		USD usd = USDServiceImpl.INSTANCE.findCurrent();
		REQUEST().setAttribute("amount", usd.getAmount());
		REQUEST().setAttribute("date", usd.getDate());
		return SUCCESS;
	}
	
	public String edit() {
		Parameter parameter = ParameterService.INSTANCE.findById(this.id);
		parameter.setValue(this.value);
		ParameterService.INSTANCE.persist(parameter);
		this.addLoggingDetail(BaseAction.EDIT, "logging.parameter.edit", parameter.getComment(), parameter.getValue());
		return NONE;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getComment() {
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}
}